package com.study.IoC;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by 汪贵春 on 2017/2/22.
 */
public class TestMain {

    public static void main(String[] args){
        //获取上下文
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        //通过id获取bean
        ScrewDriver screwDriver = context.getBean("screwDriver",ScrewDriver.class);
        Header header = context.getBean("header",StraightHeader.class);

        screwDriver.useScrew();
        header.doWork();

        //关闭上下文
        ((ConfigurableApplicationContext)context).close();
    }
}
